package com.audition.thread.threadsecurity;

/**
 * @author xukang
 * @date 2021-03-08 15:57
 */
public class WrongResult {
    volatile static int i;

    public static void main(String[] args) throws InterruptedException {
        Runnable r = new Runnable() {
            @Override
            public void run() {
                for (int j = 0; j < 10000; j++) {
                    i++;//因为i++不是原子操作
                }
            }
        };
        Thread thread1 = new Thread(r);
        thread1.start();
        Thread thread2 = new Thread(r);
        thread2.start();
        thread1.join();
        thread2.join();
        System.out.println(i);
    }
}

